/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-12-01 10:45:52
 * @LastEditors: 商晓彬
 * @LastEditTime: 2022-01-04 14:37:58
 */
import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';
import { LazyLoadEvent } from 'primeng/api';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { ProductionReviewServiceProxy, CommonServiceProxy, SuiteInfoBoardServiceProxy, } from '@shared/service-proxies/service-proxies';
import * as moment from 'moment';
import { MatchingInnerComponent } from './matching-inner/matching-inner.component';
import { MatchingSumComponent } from './matching-sum/matching-sum.component';
@Component({
    selector: 'app-rocket-matching-kanban',
    templateUrl: './rocket-matching-kanban.component.html',
    styleUrls: ['./rocket-matching-kanban.component.less']
})
export class RocketMatchingKanbanComponent extends AppComponentBase {
    @ViewChild('MatchingInnerComponent') MatchingInnerComponent: MatchingInnerComponent;
    @ViewChild('MatchingSumComponent') MatchingSumComponent: MatchingSumComponent;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _productionReviewServiceProxy: ProductionReviewServiceProxy,
        private _commonServiceProxy: CommonServiceProxy,
        private _suiteInfoBoardServiceProxy: SuiteInfoBoardServiceProxy,
    ) {
        super(injector);
    }
    fullScreen = false;
    model = undefined;
    modelOptions = [];
    topForm = {
        quantity: undefined, preSuiteQuantity: undefined,
        preSuitePercent: undefined, suiteQuantity: undefined,
        suitePercent: undefined, outboundQuantity: undefined,
        outboundPercent: undefined
    };
    selectData = [];
    selectForm = {
        title: undefined, id: undefined,
        quantity: undefined, preSuiteQuantity: undefined,
        preSuitePercent: undefined, suiteQuantity: undefined,
        suitePercent: undefined, outboundQuantity: undefined,
        outboundPercent: undefined
    };
    rockName = '';
    chooseIndex = 0;
    setTimeoutData() {
        abp.ui.setBusy();
        this._suiteInfoBoardServiceProxy.getNodeDropList(
            this.model
        )
            .pipe(finalize(() => { })).subscribe(result => {
                abp.ui.clearBusy();
                this.topForm.quantity = result.quantity;
                this.topForm.preSuiteQuantity = result.preSuiteQuantity;
                this.topForm.preSuitePercent = result.preSuitePercent;
                this.topForm.suiteQuantity = result.suiteQuantity;
                this.topForm.suitePercent = result.suitePercent;
                this.topForm.outboundQuantity = result.outboundQuantity;
                this.topForm.outboundPercent = result.outboundPercent;
                this.selectData = result.boardXJLists;

                this.selectData[this.chooseIndex].isUsed = 1;
                this.selectForm.id = this.selectData[this.chooseIndex].id;
                this.selectForm.title = this.selectData[this.chooseIndex].name;
                this.selectForm.quantity = this.selectData[this.chooseIndex].quantity;
                this.selectForm.preSuiteQuantity = this.selectData[this.chooseIndex].preSuiteQuantity;
                this.selectForm.preSuitePercent = this.selectData[this.chooseIndex].preSuitePercent;
                this.selectForm.suiteQuantity = this.selectData[this.chooseIndex].suiteQuantity;
                this.selectForm.suitePercent = this.selectData[this.chooseIndex].suitePercent;
                this.selectForm.outboundQuantity = this.selectData[this.chooseIndex].outboundQuantity;
                this.selectForm.outboundPercent = this.selectData[this.chooseIndex].outboundPercent;
            })
    }
    openPreMathing() {
        //预配套
        this.MatchingInnerComponent.show();
    }
    openMathing() {
        //配套
        this.MatchingSumComponent.show();
    }
    getLeftDown(item, index) {
        setTimeout(() => {
            this.chooseIndex = index;
            //根据火箭种类获取配套信息
            let oldData = this.selectData;
            // this.selectData = [];
            for (let i = 0; i < oldData.length; i++) {
                const item = oldData[i];
                if (i == index) {
                    item.isUsed = 1;
                    this.selectForm.id = item.id;
                    this.selectForm.title = item.name;
                    this.selectForm.quantity = item.quantity;
                    this.selectForm.preSuiteQuantity = item.preSuiteQuantity;
                    this.selectForm.preSuitePercent = item.preSuitePercent;
                    this.selectForm.suiteQuantity = item.suiteQuantity;
                    this.selectForm.suitePercent = item.suitePercent;
                    this.selectForm.outboundQuantity = item.outboundQuantity;
                    this.selectForm.outboundPercent = item.outboundPercent;
                } else {
                    item.isUsed = 0;
                }
            }
            let rockName = this.rockName.split('-');
            this.rockName = rockName[0];
            this.rockName = this.rockName + this.getPhotoName(item.name);
        }, 10);
    }
    ngOnInit() {
        setInterval(() => {
            this.setTimeoutData();
        }, 3600000);
        abp.ui.setBusy();
        //型号
        this._suiteInfoBoardServiceProxy.getModelLotNoForBoard(
        )
            .pipe(finalize(() => { })).subscribe(result => {
                this.modelOptions = result;
                this.model = result[0].value;
                this._suiteInfoBoardServiceProxy.getNodeDropList(
                    this.model
                )
                    .pipe(finalize(() => { })).subscribe(result => {
                        abp.ui.clearBusy();
                        this.topForm.quantity = result.quantity;
                        this.topForm.preSuiteQuantity = result.preSuiteQuantity;
                        this.topForm.preSuitePercent = result.preSuitePercent;
                        this.topForm.suiteQuantity = result.suiteQuantity;
                        this.topForm.suitePercent = result.suitePercent;
                        this.topForm.outboundQuantity = result.outboundQuantity;
                        this.topForm.outboundPercent = result.outboundPercent;
                        this.selectData = result.boardXJLists;
                        if (this.selectData.length >= 1) {
                            let name = '';
                            for (const item of this.selectData) {
                                name = name + item.name;
                                item.isUsed = 0;
                            }
                            this.rockName = this.getTypeName(name);
                            this.rockName = this.rockName + this.getPhotoName(this.selectData[0].name);
                            this.selectData[0].isUsed = 1;
                            this.selectForm.id = this.selectData[0].id;
                            this.selectForm.title = this.selectData[0].name;
                            this.selectForm.quantity = this.selectData[0].quantity;
                            this.selectForm.preSuiteQuantity = this.selectData[0].preSuiteQuantity;
                            this.selectForm.preSuitePercent = this.selectData[0].preSuitePercent;
                            this.selectForm.suiteQuantity = this.selectData[0].suiteQuantity;
                            this.selectForm.suitePercent = this.selectData[0].suitePercent;
                            this.selectForm.outboundQuantity = this.selectData[0].outboundQuantity;
                            this.selectForm.outboundPercent = this.selectData[0].outboundPercent;
                        }
                    });
            });
    }
    getTypeName(name) {
        if (name.indexOf("芯二级") == -1) {
            //无芯二级
            if (name.indexOf("助推Ⅱ") == -1) {
                //无助推
                return 'rock7';
            } else {
                if (name.indexOf("助推Ⅳ") == -1) {
                    //判断有两个助推还是四个助推
                    //两个助推
                    return 'rock4';
                } else {
                    return 'rock1';
                }
            }
        } else {
            //判断是否有新三级
            if (name.indexOf("芯三级") == -1) {
                //不存在芯三级
                if (name.indexOf("助推Ⅱ") == -1) {
                    //无助推
                    return 'rock8';
                } else {
                    //判断几个助推
                    if (name.indexOf("助推Ⅳ") == -1) {
                        //判断有两个助推还是四个助推
                        //两个助推
                        return 'rock5';
                    } else {
                        return 'rock2';
                    }
                }
            } else {
                if (name.indexOf("助推Ⅱ") == -1) {
                    //无助推
                    return 'rock9';
                } else {
                    //判断几个助推
                    if (name.indexOf("助推Ⅳ") == -1) {
                        //判断有两个助推还是四个助推
                        //两个助推
                        return 'rock6';
                    } else {
                        return 'rock3';
                    }
                }
            }
        }
    }
    getPhotoName(name) {
        let type = this.rockName.split('rock');
        switch (type[1]) {
            case '1':
                return this.getType1(name);
            case '2':
                return this.getType2(name);
            case '3':
                return this.getType3(name);
            case '4':
                return this.getType4(name);
            case '5':
                return this.getType5(name);
            case '6':
                return this.getType6(name);
            case '7':
                return this.getType7(name);
            case '8':
                return this.getType8(name);
            case '9':
                return this.getType9(name);
            default:
                return '-1';
        }
    }
    getType1(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '星罩':
                return "-2";
            case '助推Ⅰ':
                return "-3";
            case '助推Ⅱ':
                return "-4";
            case '助推Ⅲ':
                return "-5";
            case '助推Ⅳ':
                return "-6";
            default:
                return "-1";
        }
    }
    getType2(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '星罩':
                return "-3";
            case '助推Ⅰ':
                return "-4";
            case '助推Ⅱ':
                return "-5";
            case '助推Ⅲ':
                return "-6";
            case '助推Ⅳ':
                return "-7";
            default:
                return "-1";
        }
    }
    getType3(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '芯三级':
                return "-3";
            case '星罩':
                return "-4";
            case '助推Ⅰ':
                return "-5";
            case '助推Ⅱ':
                return "-6";
            case '助推Ⅲ':
                return "-7";
            case '助推Ⅳ':
                return "-8";
            default:
                return "-1";
        }
    }
    getType4(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '星罩':
                return "-2";
            case '助推Ⅰ':
                return "-3";
            case '助推Ⅱ':
                return "-4";
            default:
                return "-1";
        }
    }
    getType5(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '星罩':
                return "-3";
            case '助推Ⅰ':
                return "-4";
            case '助推Ⅱ':
                return "-5";
            default:
                return "-1";
        }
    }
    getType6(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '芯三级':
                return "-3";
            case '星罩':
                return "-4";
            case '助推Ⅰ':
                return "-5";
            case '助推Ⅱ':
                return "-6";
            default:
                return "-1";
        }
    }
    getType7(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '星罩':
                return "-2";
            default:
                return "-1";
        }
    }
    getType8(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '星罩':
                return "-3";
            default:
                return "-1";
        }
    }
    getType9(name) {
        switch (name) {
            case '芯一级':
                return "-1";
            case '芯二级':
                return "-2";
            case '芯三级':
                return "-3";
            case '星罩':
                return "-4";
            default:
                return "-1";
        }
    }
    onchange(event) {
        abp.ui.setBusy();
        this._suiteInfoBoardServiceProxy.getNodeDropList(
            this.model
        )
            .pipe(finalize(() => { })).subscribe(result => {
                abp.ui.clearBusy();
                this.topForm.quantity = result.quantity;
                this.topForm.preSuiteQuantity = result.preSuiteQuantity;
                this.topForm.preSuitePercent = result.preSuitePercent;
                this.topForm.suiteQuantity = result.suiteQuantity;
                this.topForm.suitePercent = result.suitePercent;
                this.topForm.outboundQuantity = result.outboundQuantity;
                this.topForm.outboundPercent = result.outboundPercent;
                this.selectData = result.boardXJLists;
                if (this.selectData.length >= 1) {
                    let name = '';
                    for (const item of this.selectData) {
                        name = name + item.name;
                        item.isUsed = 0;
                    }
                    this.rockName = '';
                    this.rockName = this.getTypeName(name);
                    this.rockName = this.rockName + this.getPhotoName(this.selectData[0].name);
                    this.selectData[0].isUsed = 1;
                    this.selectForm.id = this.selectData[0].id;
                    this.selectForm.title = this.selectData[0].name;
                    this.selectForm.quantity = this.selectData[0].quantity;
                    this.selectForm.preSuiteQuantity = this.selectData[0].preSuiteQuantity;
                    this.selectForm.preSuitePercent = this.selectData[0].preSuitePercent;
                    this.selectForm.suiteQuantity = this.selectData[0].suiteQuantity;
                    this.selectForm.suitePercent = this.selectData[0].suitePercent;
                    this.selectForm.outboundQuantity = this.selectData[0].outboundQuantity;
                    this.selectForm.outboundPercent = this.selectData[0].outboundPercent;
                }
            })
    }
    full() {
        if (!this.fullScreen) {
            const docElmWithBrowsersFullScreenFunctions = document.getElementById('main') as HTMLElement & {
                webkitRequestFullscreen(): Promise<void>;
            };
            if (docElmWithBrowsersFullScreenFunctions.requestFullscreen) {
                docElmWithBrowsersFullScreenFunctions.requestFullscreen();
            } else if (docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
                docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen();
            }
            this.fullScreen = true;
        } else {
            const docWithBrowsersExitFunctions = document as Document & {
                webkitExitFullscreen(): Promise<void>;
            };
            if (docWithBrowsersExitFunctions.exitFullscreen) {
                docWithBrowsersExitFunctions.exitFullscreen();
            } else if (docWithBrowsersExitFunctions.webkitExitFullscreen) { /* Chrome, Safari and Opera */
                docWithBrowsersExitFunctions.webkitExitFullscreen();
            }
            this.fullScreen = false;
        }
    }
}
